package com.halixun.d2app.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.holder.OtherPrintViewHolder;
import com.halixun.d2app.adapter.holder.UsbPrintViewHolder;
import com.halixun.d2app.base.BasePrintInfo;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.net.errer.ResultVerifier;

import java.util.List;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter
 * @ClassName: PrintListAdapter
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/8 14:48
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/8 14:48
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class PrintListAdapter extends RecyclerView.Adapter<BaseViewHolder<BasePrintInfo>> {

    private List<? extends BasePrintInfo> infos;

    private LayoutInflater layoutInflater;

    private PrintListListener mPrintListListener;

    public PrintListAdapter(List<? extends BasePrintInfo> infos) {
        this.infos = infos;
    }

    @NonNull
    @Override
    public BaseViewHolder<BasePrintInfo> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (layoutInflater == null) {
            layoutInflater = LayoutInflater.from(parent.getContext());
        }
        switch (viewType) {
            case BasePrintInfo.BLEU_TOOTH_PRINT:
            case BasePrintInfo.NET_PRINT:
                return new OtherPrintViewHolder(layoutInflater.inflate(R.layout.other_print_item, parent, false),mPrintListListener);
            default:
                return new UsbPrintViewHolder(layoutInflater.inflate(R.layout.usb_print_item, parent, false),mPrintListListener);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return infos.get(position).type;
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<BasePrintInfo> holder, int position) {
        holder.setLayoutInfo(infos.get(position));
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }

    public void setPrintListListener(PrintListListener listListener){
        this.mPrintListListener = listListener;
    }

    public interface PrintListListener{
        void onPrintListItemClick(int position,BasePrintInfo info);

        void onLongPrintListItemClick(int position, BasePrintInfo data);
    }

}
